from starlette.middleware.base import BaseHTTPMiddleware
from fastapi import Request, Response
class AuthMiddleware(BaseHTTPMiddleware):
    async def dispatch(self, request: Request, call_next):
        token = request.headers.get("Authorization")
        if not token and request.url.path != "/login":
            return Response("Unauthorized", status_code=401)
        response = await call_next(request)
        return response
